package org.snw;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        NodeWeight s1 = new NodeWeight("SYS1", 3);
        NodeWeight s2 = new NodeWeight("SYS2", 1);
        NodeWeightSet set = new NodeWeightSet(s1, s2);
        final NodeSelector nodeSelector = new NodeSelector(set);
        int threadNum = 10;
        int times = 12000;
        AtomicInteger sys1 = new AtomicInteger(0);
        AtomicInteger sys2 = new AtomicInteger(0);
        ExecutorService pool = Executors.newFixedThreadPool(threadNum);
        for (int i = 0; i < threadNum; i++) {
            pool.execute(() -> {
                for (int j = 0; j < times; j++) {
                    NodeWeight select = nodeSelector.select();
                    if ("SYS1".equals(select.getName())) {
                        sys1.incrementAndGet();
                    } else {
                        sys2.incrementAndGet();
                    }
                }
            });
        }
        Thread.sleep(1000);
        pool.shutdown();
        System.out.println("sys1:" + sys1.get());
        System.out.println("sys2:" + sys2.get());
    }
}
